
#ifndef RTHTTPPROXYSETTING_H
#define RTHTTPPROXYSETTING_H

#include "RtStdCpp.h"

class /*RT_API_EXPORT*/ IRtHttpProxySetting
{
public:
	typedef enum { 
		BROWSER_IE,			// all versions of IE
		BROWSER_NETSCAPE1,	// netscape 4.x
		BROWSER_NETSCAPE2,	// netscape 6.x and above
		BROWSER_FIREFOX,	// firefox
		BROWSER_OTHER		// other
	} BrowseType;

	//if success, return TRUE, otherwise return FALSE;
	virtual BOOL GetProxySetting(
		CRtString &aWpad,			// url string for wpad, only exists in IE
		CRtString &aAutoConfigURL,	// auto config url, like http://address/pacfile
		CRtString &aManual,			// it should be like "http=httpip:httpport;https=httpsip:httpsport;socks[5]=socksip:socksport"
		CRtString &aByPass,			// the ip addresses which don't need proxy, only for manual setting 
		BrowseType &aType			// IE or Netscape 
		) = 0;

	virtual ~IRtHttpProxySetting() { }
};

#ifdef RT_WIN32

#include "RtReferenceControl.h"
#include "RtHttpInterface.h"
#include <vector>

class CRtHttpProxySettingWin32 : public IRtHttpProxySetting
{
public:
	CRtHttpProxySettingWin32();
	virtual ~CRtHttpProxySettingWin32();
	
	virtual BOOL GetProxySetting(
			CRtString &aWpad, 
			CRtString &aAutoConfigURL,
			CRtString &aManual, 
			CRtString &aByPass,
			BrowseType &aType);

private:
	BOOL Init();
	BOOL GetDefaultBrowser();
	BOOL GetIESetting();
	BOOL GetIEWpadSetting();
	BOOL GetNetscapeSetting(IRtHttpProxySetting::BrowseType aBrowserType);

	class CNetscapePrefGet
		: public CRtReferenceControlSingleThread
		, public IRtChannelSink
	{
	public:
		CNetscapePrefGet(CRtHttpProxySettingWin32* aSetting);
		virtual ~CNetscapePrefGet();

		BOOL Init(const CRtString &aPathName);

		// interface IRtChannelSink
		virtual void OnConnect(RtResult aReason, IRtChannel *aChannelId);

		// interface IRtTransportSink
		virtual void OnReceive(
			CRtMessageBlock &aData,
			IRtTransport *aTrptId,
			CRtTransportParameter *aPara = NULL);

		virtual void OnSend(
			IRtTransport *aTrptId,
			CRtTransportParameter *aPara = NULL);

		virtual void OnDisconnect(
			RtResult aReason,
			IRtTransport *aTrptId);

	private:
		CRtHttpProxySettingWin32* m_pSetting;
		CRtAutoPtr<IRtChannel> m_pFileChannel;
	};
	friend class CNetscapePrefGet;

	CRtAutoPtr<CNetscapePrefGet> m_pNetscapePrefGet;
	BrowseType  m_BrowserType;
	CRtString m_strWpad;
	CRtString m_strAutoConfigURL;
	CRtString m_strManual;
	CRtString m_strByPass;
};

#endif // RT_WIN32

#endif // !RTHTTPPROXYSETTING_H
